package com.yand.rabbitmq;


import com.yand.api.entity.mq.MyMessage;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class RabbitMQProducer {

    @Autowired
    private AmqpTemplate rabbitTemplate;

    public void stringSend() {
        Date date = new Date();
        String dateString = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
        System.out.println("[string] send msg:" + dateString);
        // 第一个参数为刚刚定义的队列名称
        rabbitTemplate.convertAndSend("exchange","testQueue", dateString);
    }

    public void sendObj(MyMessage message){
        rabbitTemplate.convertAndSend("exchange","testQueue", message);
    }
}
